﻿using EasyERP_DAL;
using EasyERP_DAL.Base;
using EasyERP_Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyERP_BLL.Base
{
    /// <summary>
    /// 税率管理业务逻辑类
    /// </summary>
    public class B_Tax_BLL
    {
        /// <summary>
        /// 声明税率管理数据访问类对象
        /// </summary>
        private readonly B_Tax_DAL Tax_DAL = new B_Tax_DAL();

        #region 获取税率表信息
        /// <summary>
        /// 获取税率表信息
        /// </summary>
        /// <returns>返回查询表</returns>
        public DataTable Get_B_Tax()
        {
            try
            {
                return Tax_DAL.Get_B_Tax();
            }
            catch (Exception ex)
            {
                B_Message_BLL.MessageCaveat(ex);
                return null;
            }
        }
        #endregion

        #region 添加税率信息
        /// <summary>
        /// 添加税率信息
        /// </summary>
        /// <param name="model">税率实体对象</param>
        /// <returns>返回True：成功；返回False：失败</returns>
        public bool Insert_B_Tax(B_Tax model)
        {
            if (string.IsNullOrWhiteSpace(model.tax_cd))                    //税率编号为空
            {
                B_Message_BLL.MessageCaveat("2008");                        //弹出提示框
                return false;
            }

            if (string.IsNullOrWhiteSpace(model.tax_nm))                    //税率名称为空
            {
                B_Message_BLL.MessageCaveat("2009");                        //弹出提示框
                return false;
            }

            if (string.IsNullOrWhiteSpace(model.tax_rate.ToString()))       //税率比例为空
            {
                B_Message_BLL.MessageCaveat("2010");                        //弹出提示框
                return false;
            }

            //保存前验证数据是否存在
            if (Tax_DAL.Exists(model))      //存在
            {
                B_Message_BLL.MessageCaveat("1001");        //弹出提示框
                return false;
            }

            try
            {
                return Tax_DAL.Insert_B_Tax(model);
            }
            catch (Exception ex)
            {
                B_Message_BLL.MessageCaveat(ex);
                return false;
            }
        }
        #endregion

        #region 删除税率信息
        /// <summary>
        /// 删除税率信息
        /// </summary>
        /// <param name="model">税率实体对象</param>
        /// <returns>返回True：成功；返回False：失败</returns>
        public bool Delete_B_Tax(B_Tax model)
        {
            //删除前验证数据是否存在
            if (Tax_DAL.Exists(model))     //不存在
            {
                try
                {
                    return Tax_DAL.Delete_B_Tax(model);
                }
                catch (Exception ex)
                {
                    B_Message_BLL.MessageCaveat(ex);
                    return false;
                }
            }
            B_Message_BLL.MessageCaveat("1002");        //弹出提示框
            return false;
        }
        #endregion

        #region 修改税率信息
        /// <summary>
        /// 修改税率信息
        /// </summary>
        /// <param name="model">税率实体对象</param>
        /// <returns>返回True：成功；返回False：失败</returns>
        public bool Update_B_Tax(B_Tax model)
        {
            if (string.IsNullOrWhiteSpace(model.tax_nm))                    //税率名称为空
            {
                B_Message_BLL.MessageCaveat("2009");                        //弹出提示框
                return false;
            }

            if (string.IsNullOrWhiteSpace(model.tax_rate.ToString()))       //税率比例为空
            {
                B_Message_BLL.MessageCaveat("2010");                        //弹出提示框
                return false;
            }

            //修改前验证数据是否存在
            if (Tax_DAL.Exists(model))     //不存在
            {
                try
                {
                    return Tax_DAL.Update_B_Tax(model);
                }
                catch (Exception ex)
                {
                    B_Message_BLL.MessageCaveat(ex);
                    return false;
                }
            }
            B_Message_BLL.MessageCaveat("1003");        //弹出提示框
            return false;
        }
        #endregion
    }
}
